﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
/// <summary>
/// AdminCs 的摘要说明
/// </summary>
//该源码下载自www.51aspx.com(５１aｓｐｘ．ｃｏｍ)

public class AdminCs
{
	public AdminCs()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}

    /// <summary>
    /// 检查登录状态
    /// </summary>
    public static void CheckLoginState()
    {
        if (HttpContext.Current.Session["Wn_Admin"] == null)
        {
            HttpContext.Current.Response.Write("<script>window.open('logout.aspx','_parent')</script>");
        }
    }
    public static void UserLoginState()
    {
        if (HttpContext.Current.Session["wj_User"] == null)
        {
           HttpContext.Current.Response.Write("<script>window.open('../uPassport.aspx','_parent')</script>");
        }
    }
    public static int Admin_Login(string strUser, string strPwd)//管理员登陆并返回管理员类型
    {
        int AdminType = -1;
        SqlConnection conn = Class1.DBconnection();
        conn.Open();
        SqlCommand cmd = new SqlCommand("C_SyAdmin", conn);
        cmd.CommandType = System.Data.CommandType.StoredProcedure;
        cmd.Parameters.Add("@AdminName", SqlDbType.VarChar, 50).Value = strUser;
        cmd.Parameters.Add("@AdminPwd", SqlDbType.VarChar, 50).Value = strPwd;
        SqlDataReader ds;
        ds = cmd.ExecuteReader();
        if (ds.Read())
        {
            AdminType = int.Parse(ds["AdminType"].ToString());
        }
        ds.Close();
        cmd.Dispose();
        conn.Close();
        return AdminType;
    }
    public static int User_Login(string strUser, string strPwd)//用户登陆
    {
        int UserType = -1;
        SqlConnection conn = Class1.DBconnection();
        conn.Open();
        SqlCommand cmd = new SqlCommand("C_wjUser", conn);
        cmd.CommandType = System.Data.CommandType.StoredProcedure;
        cmd.Parameters.Add("@User", SqlDbType.VarChar, 50).Value = strUser;
        cmd.Parameters.Add("@Pwd", SqlDbType.VarChar, 50).Value = strPwd;
        SqlDataReader ds;
        ds = cmd.ExecuteReader();
        if (ds.Read())
        {
            UserType = int.Parse(ds["wj_Type"].ToString());
        }
        ds.Close();
        cmd.Dispose();
        conn.Close();
        return UserType;
    }
}
